package org.jeecg.modules.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.wms.entity.WmsSupplierMaterial;
import org.jeecg.modules.wms.mapper.WmsSupplierMaterialMapper;
import org.jeecg.modules.wms.service.IWmsSupplierMaterialService;
import org.jeecg.modules.wms.vo.WmsSupplierMaterialVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description: 供应商物料关联表
 * @Author: jeecg-boot
 * @Date: 2023-07-18
 * @Version: V1.0
 */
@Service
public class WmsSupplierMaterialServiceImpl extends ServiceImpl<WmsSupplierMaterialMapper, WmsSupplierMaterial> implements IWmsSupplierMaterialService {

    @Override
    public List<WmsSupplierMaterial> listBySupplier(String supplierId) {
        LambdaQueryWrapper<WmsSupplierMaterial> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WmsSupplierMaterial::getSupplierId, supplierId);
        return this.list(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveBatch(String supplierId, List<WmsSupplierMaterial> materialList) {
        // 设置供应商ID
        materialList.forEach(material -> material.setSupplierId(supplierId));
        return this.saveBatch(materialList);
    }

    @Override
    public boolean deleteBySupplier(String supplierId) {
        LambdaQueryWrapper<WmsSupplierMaterial> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WmsSupplierMaterial::getSupplierId, supplierId);
        return this.remove(queryWrapper);
    }

    @Override
    public List<WmsSupplierMaterialVO> getSuppliersByMaterialCode(String materialCode) {
        return baseMapper.getSuppliersByMaterialCode(materialCode);
    }
    
    @Override
    public List<WmsSupplierMaterialVO> getAllSuppliers() {
        return baseMapper.getAllSuppliers();
    }
} 